home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / btnc200 / btnc.c next >
C/C++ Source or Header  |  1996-09-10  |  10KB  |  524 lines

  1. /*
  2. **    Program:    BTNC
  3. **
  4. **    Module:        Main
  5. */
  6.  
  7.  
  8. #include        <portab.h>
  9.  
  10. #include        <stdio.h>
  11. #include        <stdlib.h>
  12. #include        <tos.h>
  13. #include        <ext.h>
  14. #include        <aes.h>
  15. #include        <string.h>
  16. #include        <time.h>
  17. #include        <misclib.h>
  18.  
  19. #include        "general.h"
  20. #include        "globals.h"
  21. #include        "messages.h"
  22. #include        "prototyp.h"
  23. #include        "logfile.h"
  24.  
  25. FILE            *NodeList,
  26.                 *AddList,
  27.                 *PointList,
  28.                 *nodeinfo_bnl,
  29.                 *index_bnl,
  30.                 *domains_bnl;
  31.  
  32. ULONG            out;
  33.  
  34. #define BETA /* D‚fini l'affichage version B‚ta */
  35.  
  36. VOID Display(VOID)
  37. {
  38.     LOCAL UWORD lastreg;
  39.     
  40.     if (!display || curreg == lastreg) return;
  41.     
  42.     if (ap_displayed)
  43.     {
  44.         ALL_puts("\n");
  45.         ap_displayed = FALSE;
  46.     }
  47.  
  48.     STD_puts("\r");
  49.     ALL_printf("Zone %3u, Region %4u", curaddr.zone, curreg);
  50.     LOG_puts("\n");
  51.             
  52.     lastreg = curreg;    
  53.     az_displayed = TRUE;
  54. }
  55.  
  56. VOID WriteEntry(INDEX *idx, SYSTEM *sys)
  57. {
  58.     static ULONG     offset = 0L;
  59.     CSYSTEM            sys_coded;
  60.  
  61.     
  62.     /*
  63.     ** Write index entry
  64.     */
  65.     
  66.     if (c_format)
  67.     {
  68.         CINDEX    newidx;
  69.         
  70.         newidx.value = idx->value;
  71.         newidx.type = idx->type;
  72.         newidx.offset = offset;
  73.  
  74.         fwrite(&newidx, sizeof(CINDEX), 1L, index_bnl);
  75.     
  76.         /*
  77.         ** Compress system entry
  78.         */
  79.     
  80.         CodeSystemEntry (sys, &sys_coded);
  81.         fwrite(&sys_coded, sys_coded.length, 1L, nodeinfo_bnl);
  82.         offset += sys_coded.length;
  83.     }
  84.     else
  85.     {
  86.         fwrite(idx, sizeof(INDEX), 1L, index_bnl);
  87.         fwrite(sys, sizeof(SYSTEM), 1L, nodeinfo_bnl);
  88.     }
  89.  
  90.     out++;
  91. }
  92.  
  93. WORD ProcessEntry(WORD type, BYTE *l, INDEX *idx, SYSTEM *sys, UWORD nl_lines)
  94. {
  95.     memset(sys, 0, sizeof(SYSTEM));
  96.     return(ParseLine(type, l, idx, sys, nl_lines));
  97. }
  98.  
  99. VOID ProcessPointlist(POINTLIST *pl)
  100. {
  101.     BYTE    NLline[256];
  102.     WORD    error;
  103.     INDEX    idx;
  104.     SYSTEM    sys;
  105.     UWORD    nl_lines = 0;
  106.             
  107.     if (display)
  108.     {
  109.         STD_puts("\n");
  110.         ALL_printf("Adding pointlist '%s' to %u:%u/%u", pl->listfile,pl->boss.zone, pl->boss.net, pl->boss.node);
  111.         ap_displayed = TRUE;
  112.     }
  113.  
  114.     PointList = fopen(pl->listfile, "r");
  115.     
  116.     FOREVER
  117.     {
  118.         if (fgets(NLline, 255, PointList) == NULL) break;
  119.         nl_lines++;
  120.         
  121.         if (*NLline == ';') continue;
  122.         if (*NLline == CTRL_Z) break;
  123.  
  124.         if (!strchr(LEGAL_CHARS, *NLline))
  125.         {
  126.             ERR_printf("\nLine %u : First character '%c' is illegal\n", nl_lines, *NLline);
  127.             continue;
  128.         }
  129.         
  130.         error = ProcessEntry(POINT, NLline, &idx, &sys, nl_lines);
  131.         sys.hubnode = 0;
  132.         
  133.         if (!error) WriteEntry(&idx, &sys);
  134.     }
  135.     
  136.     fclose(PointList);
  137. }
  138.  
  139. VOID ProcessAddlist(ADDLIST *al)
  140. {
  141.     BYTE            NLline[256];
  142.     WORD            error;
  143.     INDEX            idx;
  144.     SYSTEM            sys;
  145.     UWORD             nl_lines = 0,
  146.                     actnet;
  147.     struct ffblk     FileRec;
  148.             
  149.     doing_addlist = TRUE;
  150.  
  151. /* Modified ----------------------------- */
  152.  
  153. /*if ( (strnicmp(al->listfile, "POINTS24", 8L) == SUCCESS)     */
  154.  
  155.     if ( (strnicmp(al->listfile, "POINTS24", 8L) == SUCCESS) 
  156.         ||  ( al->new_3D_format==TRUE) )
  157.     
  158.         points24 = TRUE;
  159.  
  160. /* -------------------------------------- */
  161.  
  162.     /*
  163.     ** Remember last net (needed to compile independant nodes in
  164.     ** a region correctly
  165.     */
  166.     
  167.     actnet = curaddr.net;
  168.     
  169.     if (findfirst(al->listfile, &FileRec, 0))
  170.     {
  171.         ERR_printf("\nNo matching file for %s !\n", al->listfile);
  172.         return;
  173.     }
  174.  
  175.  
  176.     AddList = fopen(FileRec.ff_name, "r");
  177.  
  178.  
  179. /* Modified ----------------------- */
  180.     
  181.     if( al->dimension4==TRUE)
  182.     {
  183.         ADDLIST4D=TRUE;
  184.     }
  185.  
  186. /* -------------------------------- */
  187.  
  188.     
  189.     if (display)
  190.     {
  191.  
  192. /* Modified ------------------------ */
  193.  
  194. /*printf("\nAdding 3D pointlist '%s'", FileRec.ff_name); */
  195.  
  196.     if ( ADDLIST4D==TRUE)
  197.     {
  198.         STD_puts("\n");
  199.         ALL_printf("Adding 4D pointlist '%s'", FileRec.ff_name);
  200.     }
  201.     else  if (al->new_3D_format==TRUE)
  202.     {
  203.         STD_puts("\n");
  204.         ALL_printf("Adding new format 3D pointlist '%s'", FileRec.ff_name);
  205.     }
  206.     else
  207.     {
  208.         STD_puts("\n");
  209.         ALL_printf("Adding 3D pointlist '%s'", FileRec.ff_name);
  210.     }
  211.  
  212. /* --------------------------------- */
  213.         ap_displayed = TRUE;
  214.     }
  215.     
  216.     FOREVER
  217.     {
  218.         if (fgets(NLline, 255, AddList) == NULL) break;
  219.         nl_lines++;
  220.         
  221.         if (*NLline == ';' ||
  222.             *NLline == 'Z' || *NLline == 'R') continue;
  223.         if (*NLline == CTRL_Z) break;
  224.         
  225.         if (!strchr(LEGAL_CHARS, *NLline))
  226.         {
  227.             ERR_printf("\nLine %u : First character '%c' is illegal\n", nl_lines, *NLline);
  228.             continue;
  229.         }
  230.         
  231.         error = ProcessEntry(NODE, NLline, &idx, &sys, nl_lines);
  232.         
  233.         if (!error)
  234.         {
  235.             if (idx.type > HOST) continue;
  236.             
  237.             WriteEntry(&idx, &sys);
  238.         }
  239.     }
  240.     
  241.     curaddr.net = actnet;
  242.     
  243.     fclose(AddList);
  244.     
  245.     doing_addlist = FALSE;
  246.     points24 = FALSE;
  247.  
  248. /* Modified ----------------- */
  249.  
  250.     ADDLIST4D=FALSE;
  251.     
  252. /* -------------------------- */
  253. }
  254.  
  255. VOID DoPointlist(VOID)
  256. {
  257.     POINTLIST    *pl = pointlists;
  258.     
  259.     while (pl)
  260.     {
  261.         if (curaddr.net == pl->boss.net &&
  262.             curaddr.node == pl->boss.node &&
  263.             curaddr.zone == pl->boss.zone)
  264.             ProcessPointlist(pl);
  265.         
  266.         pl = pl->next;
  267.     }
  268. }
  269.  
  270. VOID DoAddlist(UWORD region, UWORD zone)
  271. {
  272.     ADDLIST    *al = addlists;
  273.     
  274.     while (al)
  275.     {
  276.         if (region == al->toregion &&
  277.             zone == al->tozone)
  278.             ProcessAddlist(al);
  279.         
  280.         al = al->next;
  281.     }
  282. }
  283.  
  284. VOID ProcessNodelist(DOMAIN *domain)
  285. {
  286.     BYTE    NLline[256];
  287.     INDEX    idx;
  288.     SYSTEM    sys;
  289.     WORD    error;
  290.     UWORD    nl_lines;
  291.         
  292.     strcpy(NLline, domain->listfile);
  293.     strtok(NLline, ".");
  294.  
  295. /* Modified ---------------- */        
  296.  
  297. /* if (display) */
  298.  
  299.     if (display && *NLline)
  300. /* ------------------------- */
  301.     {
  302.  
  303.         ALL_printf("\n\n==================================================\n"
  304.                 "Processing %s using %s of day #%s\n"
  305.                 "==================================================\n\n",
  306.                 domain->name, strtok(NLline, "."), strtok(NULL, "."));
  307.  
  308.         az_displayed = FALSE;
  309.     }
  310.     
  311.     onlyzone = domain->zone;
  312.     nl_lines = 0;
  313.     lastreg = 0;
  314.             
  315.     FOREVER
  316.     {
  317.         if (fgets(NLline, 255, NodeList) == NULL) break;
  318.         nl_lines++;
  319.         
  320.         if (*NLline == ';') continue;
  321.         if (*NLline == CTRL_Z) break;
  322.                 
  323.         if (!strchr(LEGAL_CHARS, *NLline))
  324.         {
  325.             ERR_printf("\nLine %u : First character '%c' is illegal\n", nl_lines, *NLline);
  326.             continue;
  327.         }
  328.         
  329.         error = ProcessEntry(NODE, NLline, &idx, &sys, nl_lines);
  330.         
  331.         if (!error || error == DOWN)
  332.         {
  333.             if (idx.type == RC)
  334.             {
  335.                 if (lastreg && lastreg != curreg)
  336.                 {
  337.                     DoAddlist(lastreg, curaddr.zone);
  338.                     lastreg = curreg;
  339.                 }
  340.                 else
  341.                     lastreg = curreg;
  342.  
  343. /* Modified ---------------------- */
  344.                     Display();
  345.             }
  346. /*            Display(); */
  347. /* ------------------------------- */
  348.             
  349.             WriteEntry(&idx, &sys);
  350.             if (error == DOWN)
  351.                 down_nodes++;
  352.             else
  353.                 active_nodes++;
  354.             
  355.             DoPointlist();
  356.         }
  357.         else
  358.         {
  359.             if (error == ABORT) break;
  360.         }
  361.     }
  362.     
  363.     if (lastreg)
  364.         DoAddlist(lastreg, curaddr.zone);
  365. }
  366.  
  367. WORD main(WORD argc, BYTE **argv)
  368. {
  369.     DOMAINSPEC    *domain;
  370.     ULONG        bufsize;
  371.     ULONG        lastnodecount = 0;
  372.     time_t        starttime;
  373.  
  374.     puts(CopyrightMessage);
  375.     
  376.     #ifdef ALPHA
  377.         puts(AlphaVersion);
  378.     #endif
  379.     #ifdef BETA
  380.         puts(BetaVersion);
  381.     #endif
  382.     
  383.     starttime = time(NULL);
  384.     
  385.     STD_printf("Parsing configuration file...\n");
  386.     ParseConfig(argc, argv);
  387.         
  388.     if (!domains)
  389.     {
  390.         ALL_puts("\nNo domain(s) defined. Bye!\n");
  391.         return(FAILURE);
  392.     }
  393.     
  394.     nodeinfo_bnl    = fopen("NODEINFO.TMP", "wb");
  395.     index_bnl        = fopen("INDEX.BNL", "wb");
  396.     domains_bnl        = fopen("DOMAINS.BNL", "wb");
  397.     
  398.     bufsize = ((ULONG)coreleft() - 128000UL) / 3L;
  399.     
  400.     if (userlist)
  401.     {
  402.         fidouser_lst = fopen(userlist_name, "w");
  403.         setvbuf(fidouser_lst, NULL, _IOFBF, bufsize);
  404.         setvbuf(nodeinfo_bnl, NULL, _IOFBF, bufsize * 2UL);
  405.     }
  406.     else
  407.         setvbuf(nodeinfo_bnl, NULL, _IOFBF, bufsize * 3UL);
  408.     
  409.     setvbuf(index_bnl, NULL, _IOFBF, 64000UL);
  410.     
  411.     /*
  412.     **    Hauptschleife
  413.     */
  414.     
  415.     domain = domains;
  416.     
  417.     while (domain)
  418.     {
  419.         lastnodecount = out;
  420.         memset(hubphone, 0, 40);
  421.                 
  422.         domain->dat.startoffset = out * sizeof(INDEX);
  423.     
  424.         NodeList = fopen(domain->dat.listfile, "r");
  425.  
  426. /* Modified ------------------------ */
  427.  
  428. /*    ProcessNodelist(&domain->dat); */
  429. /*    fclose(NodeList);              */
  430.  
  431.         if(NodeList!=NULL)
  432.         {
  433.             ProcessNodelist(&domain->dat);
  434.             fclose(NodeList);
  435.     
  436.             domain->dat.length = out - lastnodecount;
  437.             fwrite(&domain->dat, sizeof(DOMAIN), 1L, domains_bnl);
  438.         }
  439.             
  440. /* ----------------------------------*/
  441.         domain = domain->next;
  442.     }
  443.     
  444.     /*
  445.     **    Files schliessen
  446.     */
  447.     
  448. /* Modified ---------------------------- */
  449.  
  450.     if (userlist)
  451.     {
  452.      if( fflush(fidouser_lst)!=0 )    write_disk_error("fidouser.lst");
  453.      fclose(fidouser_lst);
  454.     }
  455.     
  456.     if( fflush(domains_bnl)!=0 )    write_disk_error("domains.bnl");
  457.     fclose(domains_bnl);
  458.         
  459.     if( fflush(index_bnl)!=0 )        write_disk_error("index.bnl");
  460.     fclose(index_bnl);
  461.  
  462.     if( fflush(nodeinfo_bnl)!=0 )    write_disk_error("nodeinfo.bnl");
  463.     fclose(nodeinfo_bnl);
  464.     
  465. /* ------------------------------------- */
  466.  
  467.     unlink("NODEINFO.BNL");
  468.     rename("NODEINFO.TMP", "NODEINFO.BNL");
  469.     
  470.     /*
  471.     **    Statistik ausgeben
  472.     */
  473.     
  474.     if (statistics)
  475.     {
  476.         ALL_puts("\n\n####################################\n");
  477.         ALL_puts("# Nodelist Output Statistics       #\n");
  478.         ALL_puts("####################################\n");
  479.         ALL_puts("+----------------------------------+\n");
  480.         ALL_printf("| Total nodes processed    | %5u |\n", active_nodes + down_nodes);
  481.         ALL_printf("| Active nodes             | %5u |\n", active_nodes);
  482.         ALL_puts("+--------------------------+-------+\n");
  483.         ALL_printf("| Nodes down               | %5u |\n", down_nodes);
  484.         ALL_printf("| Private nodes            | %5u |\n", private_nodes);
  485.         ALL_puts("+--------------------------+-------+\n");
  486.         ALL_printf("| Zones                    | %5u |\n", zones);
  487.         ALL_printf("| Regions                  | %5u |\n", regions);
  488.         ALL_puts("+----------------------------------+\n\n");
  489.  
  490.         ALL_printf("Required: %lu seconds.\n", time(NULL) - starttime);
  491.     }
  492.  
  493.     /*
  494.     ** Send Message
  495.     */
  496.     
  497.     {
  498.         BYTE    *var,
  499.                 *semperpath,
  500.                 *hilf;
  501.     
  502.         var = getenv("SEMPER");
  503.     
  504.         semperpath = (var) ? strdup(var) : ".\\SEMPER\\";
  505.     
  506.         if (semperpath && Last(semperpath) != '\\')
  507.         {
  508.             hilf = calloc(strlen(semperpath) + 1, sizeof(BYTE));
  509.         
  510.             sprintf(hilf, "%s\\", semperpath);
  511.         
  512.             free(semperpath);
  513.             semperpath = hilf;
  514.         }
  515.     
  516.         SendAppMsg(semperpath, "READNIDX.SYS", "SEMPER  ", FM_NLCOMPILER, SEMP_READ_NLIST);
  517.     }
  518.     
  519.     logfile_close();
  520.     return(SUCCESS);
  521. }
  522.  
  523. /* ---------------- EOF -------------------- */
  524.